package com.heifeng.cloudshelf.mvp.search.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.dao.SearchDefaultBean;
import com.heifeng.cloudshelf.mvp.search.activity.SearchHouseActivity;
import com.heifeng.cloudshelf.utils.DensityUtils;

import java.util.List;

/**
 * Created by admin on 2019/9/16.
 */

public class SearchNoDataRvAdapter extends BaseQuickAdapter<List<SearchDefaultBean>, BaseViewHolder> {
    public SearchNoDataRvAdapter(Context context, int layoutResId, @Nullable List<List<SearchDefaultBean>> data) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, List<SearchDefaultBean> item) {
        LinearLayout.LayoutParams layoutParamsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParamsL.width = DensityUtils.dp2px(mContext, 186);
        layoutParamsL.setMargins(DensityUtils.dp2px(mContext, 10), DensityUtils.dp2px(mContext, 40), DensityUtils.dp2px(mContext, 10), 0);

        LinearLayout.LayoutParams layoutParamsBottom = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParamsBottom.width = DensityUtils.dp2px(mContext, 186);
        layoutParamsBottom.setMargins(DensityUtils.dp2px(mContext, 10), DensityUtils.dp2px(mContext, 22), DensityUtils.dp2px(mContext, 10), 0);


        helper.getView(R.id.l_no_data).setLayoutParams(layoutParamsL);
        helper.getView(R.id.l_no_data_bottom).setLayoutParams(layoutParamsBottom);

        LinearLayout.LayoutParams layoutParamsIv = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParamsIv.height = DensityUtils.dp2px(mContext, 140);
        helper.getView(R.id.iv_image).setLayoutParams(layoutParamsIv);
        helper.getView(R.id.iv_image_bottom).setLayoutParams(layoutParamsIv);

        if (item.size() > 0) {
            Glide.with(mContext).load(item.get(0).getImageUrl()).into((ImageView) helper.getView(R.id.iv_image));
            helper.setText(R.id.tv_title, item.get(0).getTitle());
            helper.setText(R.id.tv_address, item.get(0).getAddress());

            helper.getView(R.id.l_no_data).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    SearchHouseActivity.open(mContext, item.get(0).getId(), item.get(0).getTitle());
                }
            });
        }

        if (item.size() > 1) {
            Glide.with(mContext).load(item.get(1).getImageUrl()).into((ImageView) helper.getView(R.id.iv_image_bottom));
            helper.setText(R.id.tv_title_bottom, item.get(1).getTitle());
            helper.setText(R.id.tv_address_bottom, item.get(1).getAddress());

            helper.getView(R.id.l_no_data_bottom).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    SearchHouseActivity.open(mContext, item.get(1).getId(), item.get(1).getTitle());
                }
            });
        }
    }
}
